<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

function SimplelistingBuildRoute(&$query)
{
        $segments = array();
	$menu = &JSite::getMenu();
	if (empty($query['Itemid'])) {
		$menuItem = &$menu->getActive();
	} else {
		$menuItem = &$menu->getItem($query['Itemid']);
	}

	if(isset($query['view']))
	{
		$view = $query['view'];
		if(empty($query['Itemid'])) {
			$segments[] = $query['view'];
		}
		unset($query['view']);
	};
        
        if (isset($query['task'])){
		$segments[] = $query['task'];
		unset($query['task']);
	};
        if(isset($query['layout']))
	{
		$segments[] = $query['layout'];
		unset($query['layout']);
	};
	if(isset($query['id']))
	{
		$segments[] = $query['id'];
		unset($query['id']);
	};
	if(isset($query['controller']))
	{
		$segments[] = $query['controller'];
		unset($query['controller']);
	};
	if(isset($query['cid'][0]))
	{
		$segments[] = $query['cid'][0];
		unset($query['cid']);
	};
	if(isset($query['fid'][0]))
	{
		$segments[] = $query['fid'][0];
		unset($query['fid']);
	};

	return $segments;
}


function SimplelistingParseRoute($segments)
{
	$vars = array();
        $count = count ( $segments);
	switch($segments[0])
	{
		case 'listings':
		$vars['view'] = 'listings';
                $catid = explode(':', $segments[0]);
                $vars['catid'] = (int)$catid[0];
		break;
            	case 'authors':
		$vars['view'] = 'authors';
                $vars['layout'] = $segments[0];
		break;
                case 'manage':
		$vars['view'] = 'manage';
                $vars['layout'] = $segments[0];
		break;
                case 'show':
		$vars['view'] = 'listing';
                $vars['task'] = $segments[0];
                $vars['cid'] = $segments[1];
		break;
                case 'showAuthor':
		$vars['view'] = 'author';
                $vars['task'] = $segments[0];
                $vars['cid'] = $segments[1];
		break;
                case 'add':
		$vars['view'] = 'manage';
                $vars['task'] = $segments[0];
                $vars['cid'] = $segments[1];
		break;
                case 'edit':
		$vars['view'] = 'manage';
                $vars['task'] = $segments[0];
                $vars['cid'] = $segments[1];
		break;
                case 'remove':
		$vars['view'] = 'manage';
                $vars['task'] = $segments[0];
                $vars['cid'] = $segments[1];
		break;
                case 'favourite':
		$vars['view'] = 'listing';
                $vars['task'] = $segments[0];
                $vars['id'] = $segments[1];
		break;
                case 'deleteFav':
		$vars['view'] = 'favourite';
                $vars['task'] = $segments[0];
                $vars['fid'] = $segments[1];
		break;
                case 'delete_main':
		$vars['view'] = 'manage';
                $vars['task'] = $segments[0];
                $vars['id'] = $segments[1];
		break;
                case 'delete_sec':
		$vars['view'] = 'manage';
                $vars['task'] = $segments[0];
                $vars['id'] = $segments[1];
		break;
	}

	return $vars;
}

